// 发送留言
$("#staywordBtn").on("click", function () {
    var staywordName = $(".staywordName").val();
    var staywordEmail = $(".staywordEmail").val();
    var staywordSubject = $(".staywordSubject").val();
    var staywordMessage = $(".staywordMessage").val();
    var reg_email = /^\w+@\w+(\.[a-zA-Z]{2,3}){1,2}$/;   // 邮箱reg
    if (staywordName != null && staywordName.length != 0) {
        if (staywordEmail != null && staywordEmail.length != 0 && reg_email.test(staywordEmail)) {
            if (staywordSubject != null && staywordSubject.length != 0) {
                if (staywordMessage != null && staywordMessage.length != 0) {
                    $.ajax({
                        type: "POST",
                        url: "/userStayWord/addStayWord",
                        data: $("#stayWordForm").serialize(),
                        dataType: "json",
                        success: function (data) {
                            switch (data.result) {
                                case 200 :
                                    $(".user-stayword-message").html("留言成功，我会尽快回复到您邮箱，谢谢").css({"color": "green"});
                                    document.getElementById("stayWordForm").reset();
                                    break;
                                case 401 :
                                    window.location.href = "/login";
                                    break;
                                default :
                                    $(".user-stayword-message").html("发送失败").css({"color": "red"});
                            }
                        },
                        error: function () {
                            $(".user-stayword-message").html("ajax 服务器错误").css({"color": "red"});
                        }
                    });
                } else {
                    $(".user-stayword-message").html("留言内容不能为空").css({"color": "red"});
                }
            } else {
                $(".user-stayword-message").html("留言主题不能为空").css({"color": "red"});
            }
        } else {
            $(".user-stayword-message").html("留言邮箱不能为空，且满足123456@qq.com的格式").css({"color": "red"});
        }
    } else {
        $(".user-stayword-message").html("留言姓名不能为空").css({"color": "red"});
    }
});